import requests
import random
from util.proxies import get_proxy_poll, get_proxies

proxy_poll = get_proxy_poll(2)

urls = [f"https://httpbin.org/get?age={i}" for i in range(100)]

while urls:

    url = urls.pop()
    proxy = random.choice(proxy_poll)

    try:
        res = requests.get(url, proxies=proxy, timeout=10)
        print(res.json())
    except requests.exceptions.ProxyError as e:
        print("代理失效，重新获取代理")
        proxy_poll.remove(proxy)
        proxy_poll.append(get_proxies())
    except Exception as e:
        urls.append(url)
